package com.clkj.xiuzheng.controller.shangcheng;

import com.clkj.xiuzheng.pojo.common.Result;
import com.clkj.xiuzheng.pojo.common.StatusCode;
import com.clkj.xiuzheng.pojo.shangcheng.CompanyCommisson;
import com.clkj.xiuzheng.pojo.shangcheng.ProductCompany;
import com.clkj.xiuzheng.pojo.shangcheng.PromoCode;
import com.clkj.xiuzheng.service.shangcheng.ScCompanyService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/ScCompany")
@CrossOrigin
    @Api(value = "/ScCompany", tags = {"Z商城推广销公司管理"})
public class ScCompanyController {

    @Autowired
    private ScCompanyService scCompanyService;

    @ApiOperation(value = "根据公司名称,入住日期 获取公司信息")
    @PostMapping("/getCompanyList")
    public Result getCompanyList(@ApiParam(name = "companyName", value = "公司名称")@RequestParam(required = false) String companyName,
                                 @ApiParam(name = "startTime", value = "开始入驻日期")@RequestParam(required = false) String startTime,
                                 @ApiParam(name = "endTime", value = "结束入住日期")@RequestParam(required = false) String endTime,
                                 @ApiParam(name = "companyId", value = "公司id")@RequestParam(required = false) Integer companyId,
                                   @RequestParam Integer pageSize,
                                   @RequestParam Integer pageNum)
    {
        try {
            PageInfo pageInfo = scCompanyService.getCompanyList(companyName,startTime,endTime,companyId,pageSize,pageNum);
            return new Result(true, StatusCode.OK,"获取成功",pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"获取失败");
        }
    }
    @ApiOperation(value = "获取公司列表不分页")
    @PostMapping("/getCompanyListNoPage")
    public Result getCompanyListNoPage()
    {
        try {
            List<ProductCompany> list = scCompanyService.getCompanyListNoPage();
            return new Result(true, StatusCode.OK,"获取成功",list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"获取失败");
        }
    }
    @ApiOperation(value = "添加推广公司")
    @PostMapping("/addCompanyList")
    public Result addCompanyList(@ApiParam(name = "companyName", value = "公司名称")@RequestParam String companyName,
                                 @ApiParam(name = "companyId", value = "主公司Id")@RequestParam Integer companyId)
    {
        try {
            scCompanyService.addCompanyList(companyName,companyId);
            return new Result(true, StatusCode.OK,"添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"添加失败");
        }
    }
    @ApiOperation(value = "根据字符串id修改公司状态为上下线")
    @PostMapping("/updateCompanyUpDown")
    public Result updateCompanyUpDown(@ApiParam(name = "Ids", value = "字符串id ,")@RequestParam String Ids,
                                      @ApiParam(name = "status", value = "0下线 1上线")@RequestParam Integer status)
    {
        try {
            scCompanyService.updateCompanyDown(Ids,status);
            return new Result(true, StatusCode.OK,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"修改失败");
        }
    }
    @ApiOperation(value = "推广公司新增推广码")
    @PostMapping("/addCompanyCode")
    public Result addCompanyCode(@ApiParam(name = "companyId", value = "推广公司Id")@RequestParam Integer companyId,@ApiParam(name = "codeNum", value = "推广码个数")@RequestParam Integer codeNum)
    {
        try {
            scCompanyService.addCompanyCode(companyId,codeNum);
            return new Result(true, StatusCode.OK,"添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"添加失败");
        }
    }
    @ApiOperation(value = "根据推广公司id获取公司获取推广码")
    @PostMapping("/getCompanyCodeList")
    public Result getCompanyCodeList(@ApiParam(name = "companyId", value = "推广公司id")@RequestParam Integer companyId,
                                     @RequestParam Integer pageSize,
                                     @RequestParam Integer pageNum)
    {
       PageInfo list = scCompanyService.getCompanyCodeList(companyId,pageSize,pageNum);
        try {
            return new Result(true, StatusCode.OK,"获取成功",list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"获取失败");
        }
    }
    @ApiOperation(value = "根据推广码id绑定推广员")
    @PostMapping("/updateCodeById")
    public Result updateCodeById(@ApiParam(name = "codeId", value = "推广码id")@RequestParam Integer codeId,
                                 @RequestParam String userPhone,
                                 @RequestParam String userName)
    {
       scCompanyService.updateCodeById(codeId,userPhone,userName);
        try {
            return new Result(true, StatusCode.OK,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"修改成功");
        }
    }
    @ApiOperation(value = "根据公司id获取全部推广员申请")
    @PostMapping("/getPromoterApplyList")
    public Result getPromoterApplyList(@ApiParam(name = "companyId", value = "公司id")@RequestParam Integer companyId,
                                       @RequestParam Integer pageSize,
                                       @RequestParam Integer pageNum,
                                       @RequestParam Integer type)
    {
        try {
            PageInfo list = scCompanyService.getPromoterApplyList(companyId,pageSize,pageNum,type);
            return new Result(true, StatusCode.OK,"获取成功",list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"修改成功");
        }
    }
    @ApiOperation(value = "根据公司id获取结算详情")
    @PostMapping("/getCompanyCommison")
    public Result getCompanyCommison(Integer companyId) {
        try {
            List<CompanyCommisson> list = scCompanyService.getCompanyCommison(companyId);
            return new Result(true, StatusCode.OK,"查询成功",list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }
    @ApiOperation(value = "根据公司id结算佣金")
    @PostMapping("/settleCompanyCommison")
    public Result settleCompanyCommison(CompanyCommisson companyCommisson){
        try {
            scCompanyService.settleCompanyCommison(companyCommisson);
            return new Result(true, StatusCode.OK,"查询成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }
    @ApiOperation(value = "根据公司id 结算日期 公司名称获取公司佣金发放信息")
    @PostMapping("/getCompanyListInfo")
    public Result getCompanyListInfo(
                                 @ApiParam(name = "companyName", value = "公司名称")@RequestParam(required = false) String companyName,
                                 @ApiParam(name = "grantTime", value = "结算日期")@RequestParam(required = false) String grantTime,
                                 @ApiParam(name = "companyId", value = "主公司id")@RequestParam(required = false) Integer companyId
                               )
    {
        try {
            Map map = scCompanyService.getCompanyListInfo(companyName,grantTime,companyId);
            return new Result(true, StatusCode.OK,"获取成功",map);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"获取失败");
        }
    }


}
